def calculate_file_checksum(filename):
    try:
        with open(filename, 'rb') as file:
            data = file.read()
            return sum(data)
    except FileNotFoundError:
        print("文件未找到，请确保文件路径正确。")
        return None
    except Exception as e:
        print(f"发生错误：{e}")
        return None

# 使用函数并打印结果
filename = r"C:\Users\A0080437\Desktop\HexTransfer\kgcb_bms_V203_6.bin"  # 替换为你的文件路径
result = calculate_file_checksum(filename)
if result is not None:
    print(f"The sum of the first 256 bytes is: {result:#04x}")  # 以十六进制形式打印结果
